package managedbeans;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class CombinationsBean {

    private String letters = "";
    private List<String> searchList = new ArrayList<String>();
    private List<String> found = new ArrayList<String>();
    private String userList;

    public String go() {
        setFound(new ArrayList<String>());
        setSearchList(Arrays.asList(userList.split("\r\n")));
        cleanList();
        permuteString("", letters);
        return "";
    }

    public void cleanList() {
        for (int i = 0; i < getSearchList().size(); i++) {
            getSearchList().set(i, getSearchList().get(i).toLowerCase());
            getSearchList().set(i, getSearchList().get(i).replaceAll(" ", ""));
        }        
    }
    
    public void permuteString(String beginningString, String endingString) {
        if (endingString.length() <= 1) {
            for (String find : getSearchList()) {
                if (find.equals("lee")) {
                    System.out.print("123");
                }
                if (find.contains(beginningString + endingString) && !getFound().contains(find)) {
                    getFound().add(find);
                }
            }
        } else {
            for (int i = 0; i < endingString.length(); i++) {
                try {
                    String newString = endingString.substring(0, i) + endingString.substring(i + 1);
                    permuteString(beginningString + endingString.charAt(i), newString);
                } catch (StringIndexOutOfBoundsException exception) {
                    exception.printStackTrace();
                }
            }
        } 
    }
    
    public String addDevonList() {
        StringBuilder testList = new StringBuilder();
        testList.append("Abbey\r\n");
        testList.append("Abbots Bickington\r\n");
        testList.append("Abbotsham\r\n");
        testList.append("Abbotskerswell\r\n");
        testList.append("Accott\r\n");
        testList.append("Alfington\r\n");
        testList.append("All Saints\r\n");
        testList.append("Aller Grove\r\n");
        testList.append("Aller\r\n");
        testList.append("Allercombe\r\n");
        testList.append("Alminstone Cross\r\n");
        testList.append("Alphington\r\n");
        testList.append("Alston\r\n");
        testList.append("Alswear\r\n");
        testList.append("Alverdiscott\r\n");
        testList.append("Alwington\r\n");
        testList.append("Appledore\r\n");
        testList.append("Appledore\r\n");
        testList.append("Arlington Beccott\r\n");
        testList.append("Arlington\r\n");
        testList.append("Ash Mill\r\n");
        testList.append("Ash Thomas\r\n");
        testList.append("Ash\r\n");
        testList.append("Ashbury\r\n");
        testList.append("Ashcombe\r\n");
        testList.append("Ashculme\r\n");
        testList.append("Ashford\r\n");
        testList.append("Ashill\r\n");
        testList.append("Ashmansworthy\r\n");
        testList.append("Ashreigney\r\n");
        testList.append("Ashwater\r\n");
        testList.append("Ashwell\r\n");
        testList.append("Atherington\r\n");
        testList.append("Aunk\r\n");
        testList.append("Avonwick\r\n");
        testList.append("Awliscombe\r\n");
        testList.append("Axmouth\r\n");
        testList.append("Axtown\r\n");
        testList.append("Aylesbeare\r\n");
        testList.append("Ayshford\r\n");
        testList.append("Babeny\r\n");
        testList.append("Badworthy\r\n");
        testList.append("Baggy Point\r\n");
        testList.append("Ballhill\r\n");
        testList.append("Bantham Cross\r\n");
        testList.append("Barbrook\r\n");
        testList.append("Barwick\r\n");
        testList.append("Batsworthy\r\n");
        testList.append("Battledown Cross\r\n");
        testList.append("Batworthy\r\n");
        testList.append("Beaford\r\n");
        testList.append("Beare\r\n");
        testList.append("Beaworthy\r\n");
        testList.append("Beer\r\n");
        testList.append("Bellever\r\n");
        testList.append("Belsford\r\n");
        testList.append("Belstone\r\n");
        testList.append("Belstone Corner\r\n");
        testList.append("Benton\r\n");
        testList.append("Bentwichen\r\n");
        testList.append("Bere Alston\r\n");
        testList.append("Bere Ferrers\r\n");
        testList.append("Berner's Cross\r\n");
        testList.append("Berry Cross\r\n");
        testList.append("Berry Down Cross\r\n");
        testList.append("Berrynarbor\r\n");
        testList.append("Berrysbridge\r\n");
        testList.append("Bickingcott\r\n");
        testList.append("Bickington\r\n");
        testList.append("Bickleigh\r\n");
        testList.append("Bicton\r\n");
        testList.append("Bishop's Nympton\r\n");
        testList.append("Bishop's Tawton\r\n");
        testList.append("Bishopsteignton\r\n");
        testList.append("Bittadon\r\n");
        testList.append("Black Dog\r\n");
        testList.append("Black Torrington\r\n");
        testList.append("Blackmoor Gate\r\n");
        testList.append("Blackpool\r\n");
        testList.append("Boasley Cross\r\n");
        testList.append("Bocombe\r\n");
        testList.append("Bodley\r\n");
        testList.append("Bodmiscombe\r\n");
        testList.append("Bolberry\r\n");
        testList.append("Bolham\r\n");
        testList.append("Bondleigh\r\n");
        testList.append("Boode\r\n");
        testList.append("Bovey Tracey\r\n");
        testList.append("Bow\r\n");
        testList.append("Bowd\r\n");
        testList.append("Bowden\r\n");
        testList.append("Bradaford\r\n");
        testList.append("Bradford\r\n");
        testList.append("Bradiford\r\n");
        testList.append("Bradstone\r\n");
        testList.append("Bradwell\r\n");
        testList.append("Bradworthy\r\n");
        testList.append("Brampford Speke\r\n");
        testList.append("Brandis Corner\r\n");
        testList.append("Branscombe\r\n");
        testList.append("Bratton Clovelly\r\n");
        testList.append("Bratton Fleming\r\n");
        testList.append("Braunton\r\n");
        testList.append("Brayford\r\n");
        testList.append("Brayfordhill\r\n");
        testList.append("Brealeys\r\n");
        testList.append("Brendon\r\n");
        testList.append("Brentor\r\n");
        testList.append("Bridestowe\r\n");
        testList.append("Bridford\r\n");
        testList.append("Bridgerule\r\n");
        testList.append("Bridgetown\r\n");
        testList.append("Broadclyst\r\n");
        testList.append("Broadhembury\r\n");
        testList.append("Broadhempston\r\n");
        testList.append("Broadwoodkelly\r\n");
        testList.append("Broadwoodwidger\r\n");
        testList.append("Brownston\r\n");
        testList.append("Brushford\r\n");
        testList.append("Buckerell\r\n");
        testList.append("Buckland Brewer\r\n");
        testList.append("Buckland Filleigh\r\n");
        testList.append("Buckland Monachorum\r\n");
        testList.append("Buckland\r\n");
        testList.append("Buckland-in-the-Moor\r\n");
        testList.append("Bucks Mills\r\n");
        testList.append("Bulkworthy\r\n");
        testList.append("Burlescombe\r\n");
        testList.append("Burlestone\r\n");
        testList.append("Burrington\r\n");
        testList.append("Burscott\r\n");
        testList.append("Bursdon\r\n");
        testList.append("Butterleigh\r\n");
        testList.append("Cabbacott\r\n");
        testList.append("Cadbury\r\n");
        testList.append("Cadeleigh\r\n");
        testList.append("Capton\r\n");
        testList.append("Challacombe\r\n");
        testList.append("Chambercombe\r\n");
        testList.append("Chardstock\r\n");
        testList.append("Chawleigh\r\n");
        testList.append("Chelfham\r\n");
        testList.append("Cheriton Bishop\r\n");
        testList.append("Cheriton Fitzpaine\r\n");
        testList.append("Chittlehampton\r\n");
        testList.append("Christow\r\n");
        testList.append("Chudleigh Knighton\r\n");
        testList.append("Churchill\r\n");
        testList.append("Clayhidon\r\n");
        testList.append("Clovelly\r\n");
        testList.append("Clyst Honiton\r\n");
        testList.append("Clyst Hydon\r\n");
        testList.append("Clyst St Lawrence\r\n");
        testList.append("Clyst St Mary\r\n");
        testList.append("Cockington\r\n");
        testList.append("Cockwood\r\n");
        testList.append("Coffinswell\r\n");
        testList.append("Colaton Raleigh\r\n");
        testList.append("Colebrooke\r\n");
        testList.append("Coleford\r\n");
        testList.append("Colyford\r\n");
        testList.append("Combe Fishacre\r\n");
        testList.append("Combe Martin\r\n");
        testList.append("Combe Pafford\r\n");
        testList.append("Combe Raleigh\r\n");
        testList.append("Combe\r\n");
        testList.append("Combebow\r\n");
        testList.append("Combeinteignhead\r\n");
        testList.append("Combpyne\r\n");
        testList.append("Combrew\r\n");
        testList.append("Cookbury\r\n");
        testList.append("Coombe, Sidmouth\r\n");
        testList.append("Coombe, Teignmouth\r\n");
        testList.append("Coombe, Tiverton\r\n");
        testList.append("Copplestone\r\n");
        testList.append("Coryton\r\n");
        testList.append("Cove\r\n");
        testList.append("Crabtree, Plymouth\r\n");
        testList.append("Crapstone\r\n");
        testList.append("Crowden\r\n");
        testList.append("Croyde\r\n");
        testList.append("Cruwys Morchard\r\n");
        testList.append("Cudlipptown\r\n");
        testList.append("Culmstock\r\n");
        testList.append("Dalwood\r\n");
        testList.append("Dawlish Warren\r\n");
        testList.append("Dean Prior\r\n");
        testList.append("Denbury\r\n");
        testList.append("Digby\r\n");
        testList.append("Doddiscombsleigh\r\n");
        testList.append("Dolton\r\n");
        testList.append("Dousland\r\n");
        testList.append("Down St Mary\r\n");
        testList.append("Down Thomas\r\n");
        testList.append("Drayford\r\n");
        testList.append("Drewsteignton\r\n");
        testList.append("Dunchideock\r\n");
        testList.append("Dunkeswell\r\n");
        testList.append("Dunsford\r\n");
        testList.append("East Anstey\r\n");
        testList.append("East Buckland\r\n");
        testList.append("East Budleigh\r\n");
        testList.append("East Down\r\n");
        testList.append("Eastington\r\n");
        testList.append("Eggesford\r\n");
        testList.append("Ellacombe\r\n");
        testList.append("Exbourne\r\n");
        testList.append("Exminster\r\n");
        testList.append("Fairmile\r\n");
        testList.append("Farringdon\r\n");
        testList.append("Farway\r\n");
        testList.append("Feniton\r\n");
        testList.append("Filleigh\r\n");
        testList.append("Fremington\r\n");
        testList.append("Frenchbeer\r\n");
        testList.append("Frithelstock\r\n");
        testList.append("Galmpton, Torbay\r\n");
        testList.append("Georgeham\r\n");
        testList.append("Gidleigh\r\n");
        testList.append("Gittisham\r\n");
        testList.append("Goodleigh\r\n");
        testList.append("Halberton\r\n");
        testList.append("Halwell\r\n");
        testList.append("Halwill\r\n");
        testList.append("Harleston\r\n");
        testList.append("Hawkchurch\r\n");
        testList.append("Heanton Punchardon\r\n");
        testList.append("Hele\r\n");
        testList.append("Hemyock\r\n");
        testList.append("Hexworthy\r\n");
        testList.append("High Bickington\r\n");
        testList.append("Higher Ashton\r\n");
        testList.append("Highweek\r\n");
        testList.append("Hingston Down\r\n");
        testList.append("Hittisleigh\r\n");
        testList.append("Holcombe Rogus\r\n");
        testList.append("Holcombe\r\n");
        testList.append("Holy City\r\n");
        testList.append("Hope Cove\r\n");
        testList.append("Horrabridge\r\n");
        testList.append("Huntsham\r\n");
        testList.append("Huntshaw\r\n");
        testList.append("Iddesleigh\r\n");
        testList.append("Ide\r\n");
        testList.append("Ilsington\r\n");
        testList.append("Instow\r\n");
        testList.append("Ipplepen\r\n");
        testList.append("Jacobstowe\r\n");
        testList.append("Kelly\r\n");
        testList.append("Kenn\r\n");
        testList.append("Kennford\r\n");
        testList.append("Kentisbeare\r\n");
        testList.append("Kenton\r\n");
        testList.append("Kilmington\r\n");
        testList.append("King's Nympton\r\n");
        testList.append("Kingskerswell\r\n");
        testList.append("Knowle\r\n");
        testList.append("Knowstone\r\n");
        testList.append("Kentisbury\r\n");
        testList.append("Lamerton\r\n");
        testList.append("Landkey\r\n");
        testList.append("Langtree\r\n");
        testList.append("Lapford\r\n");
        testList.append("Lee Bay\r\n");
        testList.append("Lee\r\n");
        testList.append("Leigham\r\n");
        testList.append("Leusdon\r\n");
        testList.append("Lew Trenchard\r\n");
        testList.append("Lifton\r\n");
        testList.append("Little Torrington\r\n");
        testList.append("Littleham\r\n");
        testList.append("Longdown\r\n");
        testList.append("Lower Ashton\r\n");
        testList.append("Lustleigh\r\n");
        testList.append("Luton\r\n");
        testList.append("Lydford\r\n");
        testList.append("Lympstone\r\n");
        testList.append("Lynmouth\r\n");
        testList.append("Luppitt\r\n");
        testList.append("Mamhead\r\n");
        testList.append("Manaton\r\n");
        testList.append("Mariansleigh\r\n");
        testList.append("Marsh Green\r\n");
        testList.append("Mary Tavy\r\n");
        testList.append("Marystow\r\n");
        testList.append("Meavy\r\n");
        testList.append("Meeth\r\n");
        testList.append("Meldon\r\n");
        testList.append("Membury\r\n");
        testList.append("Merrivale\r\n");
        testList.append("Meshaw\r\n");
        testList.append("Millbridge\r\n");
        testList.append("Molland\r\n");
        testList.append("Morchard Bishop\r\n");
        testList.append("Morebath\r\n");
        testList.append("Mortehoe\r\n");
        testList.append("Mullacott\r\n");
        testList.append("Musbury\r\n");
        testList.append("Marwood\r\n");
        testList.append("Nether Exe\r\n");
        testList.append("New Quay\r\n");
        testList.append("Newton Downs\r\n");
        testList.append("Newton Ferrers\r\n");
        testList.append("Newton Poppleford\r\n");
        testList.append("Newton St Cyres\r\n");
        testList.append("Newton St Petrock\r\n");
        testList.append("Nomansland\r\n");
        testList.append("North Molton\r\n");
        testList.append("Northleigh\r\n");
        testList.append("Northlew\r\n");
        testList.append("Noss Mayo\r\n");
        testList.append("Nymet Rowland\r\n");
        testList.append("Oakford\r\n");
        testList.append("Oakfordbridge\r\n");
        testList.append("Odam Barton\r\n");
        testList.append("Odham\r\n");
        testList.append("Offwell\r\n");
        testList.append("Olchard\r\n");
        testList.append("Oldborough\r\n");
        testList.append("Otterton\r\n");
        testList.append("Parkham\r\n");
        testList.append("Parracombe\r\n");
        testList.append("Peter Tavy\r\n");
        testList.append("Peters Marland\r\n");
        testList.append("Petrockstowe\r\n");
        testList.append("Pilton\r\n");
        testList.append("Plymtree\r\n");
        testList.append("Ponsworthy\r\n");
        testList.append("Poundsgate\r\n");
        testList.append("Puddington\r\n");
        testList.append("Puslinch\r\n");
        testList.append("Putsborough\r\n");
        testList.append("Pyworthy\r\n");
        testList.append("Queen's Nympton\r\n");
        testList.append("Rackenford\r\n");
        testList.append("Raymond's Hill\r\n");
        testList.append("Rewe\r\n");
        testList.append("Riddlecombe\r\n");
        testList.append("Roborough\r\n");
        testList.append("Rockbeare\r\n");
        testList.append("Rousdon\r\n");
        testList.append("St Giles in the Wood\r\n");
        testList.append("St Sidwells\r\n");
        testList.append("Salcombe Regis\r\n");
        testList.append("Sampford Courtenay\r\n");
        testList.append("Sampford Peverell\r\n");
        testList.append("Sandford\r\n");
        testList.append("Saunton\r\n");
        testList.append("Scorriton\r\n");
        testList.append("Shaldon\r\n");
        testList.append("Shebbear\r\n");
        testList.append("Sheepstor\r\n");
        testList.append("Sheepwash\r\n");
        testList.append("Shillingford St. George\r\n");
        testList.append("Shillingford\r\n");
        testList.append("Shute\r\n");
        testList.append("Sidbury\r\n");
        testList.append("Sidford\r\n");
        testList.append("Silverton\r\n");
        testList.append("Smallridge\r\n");
        testList.append("South Tawton\r\n");
        testList.append("South Zeal\r\n");
        testList.append("Southleigh\r\n");
        testList.append("Sowton\r\n");
        testList.append("Spreyton\r\n");
        testList.append("Starcross\r\n");
        testList.append("Stibb Cross\r\n");
        testList.append("Sticklepath\r\n");
        testList.append("Stockland\r\n");
        testList.append("Stockley\r\n");
        testList.append("Stoke Canon\r\n");
        testList.append("Stoke Fleming\r\n");
        testList.append("Stoke Rivers\r\n");
        testList.append("Stokeinteignhead\r\n");
        testList.append("Stoodleigh\r\n");
        testList.append("Street\r\n");
        testList.append("Strete\r\n");
        testList.append("Swimbridge\r\n");
        testList.append("Taddiport\r\n");
        testList.append("Talaton\r\n");
        testList.append("Tawstock\r\n");
        testList.append("Tedburn St Mary\r\n");
        testList.append("Tetcott\r\n");
        testList.append("Thornbury\r\n");
        testList.append("Thorverton\r\n");
        testList.append("Throwleigh\r\n");
        testList.append("Tipton St John\r\n");
        testList.append("Trentishoe\r\n");
        testList.append("Trusham\r\n");
        testList.append("Twitchen\r\n");
        testList.append("Two Mile Oak Cross\r\n");
        testList.append("Tytherleigh\r\n");
        testList.append("Uffculme\r\n");
        testList.append("Umberleigh\r\n");
        testList.append("Uplyme\r\n");
        testList.append("Upottery\r\n");
        testList.append("Upton Hellions\r\n");
        testList.append("Upton Pyne\r\n");
        testList.append("Virginstow\r\n");
        testList.append("Walkhampton\r\n");
        testList.append("Week\r\n");
        testList.append("Welcombe\r\n");
        testList.append("West Buckland\r\n");
        testList.append("West Down\r\n");
        testList.append("West Down\r\n");
        testList.append("West Hill\r\n");
        testList.append("Westleigh\r\n");
        testList.append("Weston\r\n");
        testList.append("Whimple\r\n");
        testList.append("Whitchurch\r\n");
        testList.append("Whitestone\r\n");
        testList.append("Whiteworks\r\n");
        testList.append("Whitford\r\n");
        testList.append("Widecombe-in-the-Moor\r\n");
        testList.append("Willand\r\n");
        testList.append("Wilmington\r\n");
        testList.append("Winkleigh\r\n");
        testList.append("Witheridge\r\n");
        testList.append("Woodacott\r\n");
        testList.append("Woodbridge\r\n");
        testList.append("Woodbury\r\n");
        testList.append("Woolacombe\r\n");
        testList.append("Woolfardisworthy\r\n");
        testList.append("Woolfardisworthy, Mid Devon\r\n");
        testList.append("Woolfardisworthy, Torridge\r\n");
        testList.append("Woollaton\r\n");
        testList.append("Woolsgrove\r\n");
        testList.append("Wotter\r\n");
        testList.append("Wrafton\r\n");
        testList.append("Yarcombe\r\n");
        testList.append("Yarnscombe\r\n");
        testList.append("Yelland\r\n");
        testList.append("Yeoford\r\n");
        testList.append("Yondertown\r\n");
        testList.append("Zeal Monachorum\r\n");
        testList.append("Plymouth\r\n");
        testList.append("Exeter\r\n");
        testList.append("Torquay\r\n");
        testList.append("Paignton\r\n");
        testList.append("Exmouth\r\n");
        testList.append("Newton Abbot\r\n");
        testList.append("Barnstaple\r\n");
        testList.append("Tiverton\r\n");
        testList.append("Brixham\r\n");
        testList.append("Teignmouth\r\n");
        testList.append("Bideford\r\n");
        testList.append("Sidmouth\r\n");
        testList.append("Dawlish\r\n");
        testList.append("Ivybridge\r\n");
        testList.append("Northam\r\n");
        testList.append("Tavistock\r\n");
        testList.append("Honiton\r\n");
        testList.append("Ilfracombe\r\n");
        testList.append("Kingsteignton\r\n");
        testList.append("Cullompton\r\n");
        testList.append("Totnes\r\n");
        testList.append("Bovey Tracey\r\n");
        testList.append("Crediton\r\n");
        testList.append("Seaton\r\n");
        testList.append("Okehampton\r\n");
        testList.append("Axminster\r\n");
        testList.append("Kingsbridge\r\n");
        testList.append("Dartmouth\r\n");
        testList.append("Great Torrington\r\n");
        testList.append("Budleigh Salterton\r\n");
        testList.append("Ottery St Mary\r\n");
        testList.append("South Molton\r\n");
        testList.append("Ashburton\r\n");
        testList.append("Chudleigh\r\n");
        testList.append("Buckfastleigh\r\n");
        testList.append("Exminster\r\n");
        testList.append("Colyton\r\n");
        testList.append("Holsworthy\r\n");
        testList.append("Bradninch\r\n");
        testList.append("Salcombe\r\n");
        testList.append("Hartland\r\n");
        testList.append("North Tawton\r\n");
        testList.append("Moretonhampstead\r\n");
        testList.append("Chagford\r\n");
        testList.append("Beer\r\n");
        testList.append("Chulmleig\r\n");
        testList.append("Hatherleigh\r\n");
        setUserList(testList.toString());
        return "";
    }
    
    public String getLetters() {
        return letters;
    }

    public void setLetters(String letters) {
        this.letters = letters;
    }

    public List<String> getFound() {
        return found;
    }

    public void setFound(List<String> found) {
        this.found = found;
    }

    public List<String> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<String> searchList) {
        this.searchList = searchList;
    }

    public String getUserList() {
        return userList;
    }

    public void setUserList(String userList) {
        this.userList = userList;
    }
}

